var rePassWord = {
	init : function() {
		// 初始化事件绑定
		rePassWord.evenBind();
	},
	evenBind:function(){
		//密码保存按钮
		$('#save-password-btn').bind('click', function() {
			
			if(!$("#rePassword-from").form('validate')){
				return;
			}
			//密码加密并返回
			var oldLoginpw = $("#oldLoginpw").val();
			var loginPW = $("#loginPW").val();
			var loginPWs = $("#loginPWs").val();
			
			$("#oldLoginpw").textbox('setValue',rePassWord.doSM3(oldLoginpw));
			$("#loginPW").textbox('setValue',rePassWord.doSM3(loginPW));
			$("#loginPWs").textbox('setValue',rePassWord.doSM3(loginPWs));
			
			$('#rePassword-from').form('submit',{ 
				url : getProjectUrl('/bfs/user/repassword'),
				onSubmit : function(param) {}, 
				success : function(data) {
					data=JSON.parse(data);
					if(data.result){
					    ShowMessage('密码修改成功!', 'info');
                        $('#rePassword-from').form('clear');
					}else{
					    if (!isEmpty(data.message)){
					        $.messager.alert({
					            title: '提示',
					            msg: data.message,
					            fn: function(){
					                $('#oldLoginpw').textbox('textbox').focus(); 
					            }
					        });
				        } else{
				            ShowMessage('操作失败!', 'error');
				        }
					}
				} 
			});
		});

		// -----------------------------------------------------------------------
		
		//取消
		$('#canncel-password-btn').bind('click', function() {
			$('#rePassword-from').form('clear');
		});
	},
    //sm3加密
    doSM3 : function(msg) {
		var msgData = CryptoJS.enc.Utf8.parse(msg);

		var md;
		var sm3keycur = new SM3Digest();
		msgData = sm3keycur.GetWords(msgData.toString());
		sm3keycur.BlockUpdate(msgData, 0, msgData.length);
		var c3 = new Array(32);
		sm3keycur.DoFinal(c3, 0);
		var hashHex = sm3keycur.GetHex(c3).toString();
		return hashHex.toUpperCase();
	}
};
